package Car.dao.impl;

import Car.dao.CarDao;
import Car.model.Car;
import Car.model.Transport;
import Car.model.spr.*;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

/**
 * Created by Новак on 27.11.2014.
 */
public class CarDaoImpl extends HibernateDaoSupport implements CarDao {
    @Override
    public List getAllCar() {
        List list=getHibernateTemplate().find("from Car ");
        return list;
    }

    @Override
    public Car getCarId(int id) {
        List list = getHibernateTemplate().find("from Car where id="+id);
        if(list.size()!=0){
            return (Car)list.get(0);}

        return null;


    }

    @Override
    public List<spr_Color> getColor() {
        List list =getHibernateTemplate().find("from spr_Color ");
        return list;
    }

    @Override
    public List<spr_Transmission> getTransmission() {
        List list =getHibernateTemplate().find("from spr_Transmission ");
        return list;
    }

    @Override
    public List<spr_Privod> getPrivod() {
        List list =getHibernateTemplate().find("from spr_Privod ");
        return list;
    }

    @Override
    public List<spr_Brand> getBrand() {
        List list =getHibernateTemplate().find("from spr_Brand ");
        return list;
    }

    @Override
    public List<spr_Currency> getCurrency() {
        List list =getHibernateTemplate().find("from spr_Currency ");
        return list;
    }

    @Override
    public List<spr_Model> getModel() {
        List list =getHibernateTemplate().find("from spr_Model ");
        return list;
    }

    @Override
    public List<spr_CarType> getCarType() {
        List list =getHibernateTemplate().find("from spr_CarType ");
        return list;
    }

    @Override
    public List<spr_Condition> getCondition() {
        List list =getHibernateTemplate().find("from spr_Condition ");
        return list;
    }

    @Override
    public List<spr_TransportType> getTransportType() {
        List list =getHibernateTemplate().find("from spr_TransportType ");
        return list;
    }

    @Override
    public List<Transport> getTransports() {
        List list =getHibernateTemplate().find("from Transport ");
        return list;
    }

    @Override
    public void addCar(Car car,Transport tr) {
        getHibernateTemplate().save(tr);
        getHibernateTemplate().save(car);

    }

    @Override
    public void addTransport(Transport tr) {
        getHibernateTemplate().save(tr);
    }
}
